home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14517 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  33 lines

  1. Path: news.uni-stuttgart.de!news
  2. From: Markus Heller <Markus.Heller@studbox.uni-stuttgart.de>
  3. Newsgroups: comp.lang.c
  4. Subject: char* still alive after free ???
  5. Date: Mon, 15 Apr 1996 17:23:22 +0200
  6. Organization: Comp.Center (RUS), U of Stuttgart, FRG
  7. Message-ID: <317269EA.11BB93C2@studbox.uni-stuttgart.de>
  8. NNTP-Posting-Host: rusxppp176.rus.uni-stuttgart.de
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.0b4CALDERA (X11; I; Linux 1.2.13 i486)
  13.  
  14. Hi,
  15.  
  16. I have a global variable :
  17.  
  18. char *text=NULL;
  19.  
  20. I want to use it to store different "strings" (at diffreent times).
  21. E.g., if I want to sore 10 characters in text, I do a 
  22. text=(char *) malloc(10*sizeof(char));
  23. When I want to use text to store 3 other characters, I first do a
  24. free(text); text=NULL; and finally a
  25. text=(char *) malloc(3*sizeof(char));
  26. But to my surprise there are still the 4thh to 10th charcter of
  27. text contained before the free(text)/malloc... ???
  28. This happens under linux, but why ?
  29. (what I want to to is to get filenames from the user and then open those
  30.  files by a function to which I pass the file name..)
  31.  
  32. Markus
  33.